package action.listener;

import engine.Vertex;
import gui.Frame;
import gui.View;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import undoredo.AbstractCommand;
import undoredo.AddVertexCommand;

public class DrawVertice implements MouseListener
{
   private View view;
   private int x, y;

   public DrawVertice(View view)
   {
      super();
      this.view = view;
   }

   public DrawVertice(View view, boolean option)
   {
      super();
      this.view = view;
   }


   @Override
   public void mouseClicked(MouseEvent e)
   {
      // TODO Auto-generated method stub
   }

   @Override
   public void mouseEntered(MouseEvent e)
   {
      // TODO Auto-generated method stub
   }

   @Override
   public void mouseExited(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

   @Override
   public void mousePressed(MouseEvent e)
   {
      // TODO Auto-generated method stub
      x = e.getX();
      y = e.getY();
      Vertex v;

      if (!view.isVertexTooClose(x, y))
      {

         final int num = view.getNumOfNode() + 1;
         v = new Vertex(x, y, "" + num);

         AbstractCommand command = new AddVertexCommand(view, v);
         command.execute();

         Frame.addCommandToStack(command);
         Frame.setUndoRedoVisible();
         view.repaint();
      }
   }

   @Override
   public void mouseReleased(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

}
